document.addEventListener('DOMContentLoaded', function() {
    // 轮播图功能
    const carousel = document.querySelector('.carousel');
    const slides = document.querySelectorAll('.slide');
    const prevBtn = document.querySelector('.prev');
    const nextBtn = document.querySelector('.next');

    let currentIndex = 0;
    const slideCount = slides.length;
    let intervalId;

    // 更新轮播位置
    function updateCarousel() {
        carousel.style.transform = `translateX(-${currentIndex * 100}%)`;
    }

    // 自动轮播
    function startAutoPlay() {
        intervalId = setInterval(() => {
            currentIndex = (currentIndex + 1) % slideCount;
            updateCarousel();
        }, 5000);
    }

    // 停止自动轮播
    function stopAutoPlay() {
        clearInterval(intervalId);
    }

    // 事件监听
    prevBtn.addEventListener('click', () => {
        currentIndex = (currentIndex - 1 + slideCount) % slideCount;
        updateCarousel();
        resetAutoPlay();
    });

    nextBtn.addEventListener('click', () => {
        currentIndex = (currentIndex + 1) % slideCount;
        updateCarousel();
        resetAutoPlay();
    });

    // 鼠标悬停控制
    carousel.addEventListener('mouseenter', stopAutoPlay);
    carousel.addEventListener('mouseleave', startAutoPlay);

    // 重置自动轮播
    function resetAutoPlay() {
        stopAutoPlay();
        startAutoPlay();
    }

    // 初始化
    updateCarousel();
    startAutoPlay();
});